package com.dkd.day20250616;

public class SolutionSearch {
    public static void main(String[] args) {
        int[] arr = {-1};
        int target = 0;
        int result = search(arr,target);
        System.out.println(result);
    }
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param nums int整型一维数组
     * @param target int整型
     * @return int整型
     */
    public static int search (int[] nums, int target) {
        // write code here
        int temp =0;
        int left = 0;
        int right =nums.length-1;
        int mid =(right-left)/2;
        while(left<right){
            if(nums[mid]<target){
                temp = mid;
                mid=left+(right-mid)/2;
                left= temp+1;
            }else if(nums[mid]>target){
                temp=mid;
                mid=left+(mid-left)/2;
                right=temp-1;
            }else{
                return mid;
            }
        }
        return -1;
    }
}
